import {NextRequest, NextResponse} from "next/server";

export const config = {
    // https://nextjs.org/docs/app/building-your-application/routing/middleware#matcher
    matcher: [
        '/((?!api/auth/*|login|register|_next/static|_next/image|.*\\.jpg|.*\\.png$).*)',
    ],
};

export function middleware(request:NextRequest) {
    // 检查请求头中的认证信息
    const auth_token = request.cookies.get("auth-token");
    if (!auth_token) {
        // 如果没有 token，重定向到登录页面
        return NextResponse.redirect(new URL('/login', request.url));
    }
    return NextResponse.next();
}


